Cloud Computing (AWS Focus)

Pelago Revolutionizes Substance Use Disorder Support with AI-Powered Personalization on AWS

Healthcare organizations globally face the complex challenge of scaling deeply personalized patient interactions while simultaneously preventing burnout among care teams and upholding rigorous quality standards. In a notable advancement, Pelago, a digital health company specializing in comprehensive substance use disorder (SUD) support, successfully developed and deployed an innovative AI-powered solution designed to address this critical bottleneck. Leveraging a suite of Amazon Web Services (AWS) tools, Pelago’s engineering team achieved this feat in an expedited two-week timeframe, demonstrating a potent model for rapid innovation within a highly regulated sector.

This groundbreaking initiative at Pelago provides invaluable insights into how serverless and AI services, including Amazon Bedrock and AWS Lambda, can be orchestrated to build an event-driven AI assistant. The resulting system generates contextually aware suggestions for care teams, enhancing efficiency without compromising the essential human-in-the-loop oversight that is non-negotiable in healthcare. This approach not only sidestepped months of traditional development work but also eliminated the significant overhead typically associated with managing complex infrastructure. The successful implementation underscores a pivotal shift towards more agile, AI-enhanced care delivery models in behavioral health, promising improved outcomes for individuals navigating recovery journeys from conditions such as alcohol, tobacco, stimulants, cannabis, and opioid use disorder.

Addressing a Critical Healthcare Challenge: The Demand for Personalized SUD Care

Substance Use Disorder remains a pervasive public health crisis. According to the Substance Abuse and Mental Health Services Administration (SAMHSA), in 2022, 48.7 million people aged 12 or older in the United States had a substance use disorder in the past year. Despite the high prevalence, access to effective and personalized treatment remains a significant barrier for many. Traditional SUD treatment, often reliant on individual coaching and therapy, inherently struggles with scalability. Care teams, comprising dedicated coaches, frequently manage dozens of active conversations concurrently. Each message exchanged must resonate with weeks or months of prior interactions, requiring coaches to manually synthesize extensive context before drafting a response. This labor-intensive process not only consumes valuable time but also increases the risk of caregiver fatigue and potential inconsistencies in care delivery.

Pelago’s mission is to bridge this gap by offering a digital clinic model that provides 1:1 coaching, medication management, and behavioral therapy across the US. As their member base expanded, the challenge of maintaining the high-touch, personalized nature of their care became increasingly pronounced. The engineering team recognized that an AI assistant, if designed correctly, could serve as a force multiplier for their coaches, enabling them to sustain personalized interactions at scale without diluting quality or overburdening staff.

The Development Sprint: Two Weeks to a Production-Ready AI Assistant

Building a serverless AI assistant at Pelago: concept to care in two weeks | Amazon Web Services

The rapid two-week development and deployment cycle for Pelago’s AI assistant stands out as a testament to both strategic planning and the capabilities of modern cloud services. This accelerated timeline, a stark contrast to the months or even years typically required for healthcare technology implementations, was meticulously structured:

  • Days 1-2: Architecture and Model Selection: The initial phase involved close collaboration between the engineering and clinical teams to define the system architecture and select appropriate AI models. This crucial period focused on understanding clinical requirements, ethical considerations, and data flow. The decision to leverage Amazon Bedrock, a fully managed service that provides access to foundation models (FMs) from leading AI companies via a single API, was pivotal. This choice allowed Pelago to benefit from advanced large language models (LLMs) without the complexities of managing underlying infrastructure or model training from scratch.
  • Days 3-5: Core Lambda Function Development: The team then focused on building the foundational AWS Lambda functions. These serverless compute services would execute the core logic for message processing, context retrieval, and AI inference. The emphasis was on creating efficient, scalable, and secure functions capable of handling Protected Health Information (PHI).
  • Days 6-8: Integration Testing and Prompt Refinement: With the core components in place, extensive integration testing commenced. This phase was critical for ensuring seamless communication between different AWS services and Pelago’s existing systems. Concurrently, prompt engineering—the art and science of crafting effective instructions for LLMs—was rigorously refined. This involved iterating on prompts to ensure the AI generated empathetic, contextually relevant, and clinically appropriate suggestions, aligning with Pelago’s care philosophy.
  • Days 9-10: Deployment and Monitoring Setup: The final days were dedicated to deploying the solution into production and establishing robust monitoring and observability frameworks. This included configuring CloudWatch alarms and dashboards to track performance, error rates, and key business metrics, ensuring the system’s reliability and allowing for continuous improvement.

This compressed timeline was made possible by the choice of serverless architecture and managed AI services, which abstract away much of the operational burden, allowing the engineering team to concentrate on core development and integration.

Architectural Foundations: Event-Driven Serverless Design on AWS

The cornerstone of Pelago’s AI assistant is an event-driven serverless architecture, meticulously designed to meet the unique demands of behavioral health conversations. These conversations unfold over extended periods, requiring an AI assistant to comprehend full, long-term conversation histories—not just recent messages. Furthermore, human oversight is paramount; the system had to generate suggestions for care teams, not automated responses, ensuring every piece of feedback is reviewed and adapted by a human coach.

The architecture ingeniously separates concerns using an event-driven paradigm. Each incoming member message is treated as an asynchronous event, allowing for parallel processing without coupling the AI generation directly to the message delivery path. This design ensures that computationally intensive AI generation, which can take several seconds for large language models (LLMs), does not block the user experience for care teams.

The end-to-end solution architecture is centered around Amazon Simple Notification Service (Amazon SNS) for message fanout and AWS Lambda functions for processing:

  1. Message Ingestion: When a member or coach sends a message within the Pelago application, the system publishes a standardized payload (containing identityId, messageId, sender, timestamp, conversationId) to an Amazon SNS topic.
  2. Fanout to Subscribers: The SNS topic, acting as a message bus, automatically delivers this event to multiple independent Lambda function subscribers in parallel.
    • A Metadata Storage Lambda writes message metadata to MySQL for reporting purposes.
    • An Analytics Lambda sends events to Amplitude for product analytics, tracking user engagement and system performance.
    • A Push Notification Lambda triggers mobile notifications, ensuring coaches are promptly alerted to new messages.
    • The dedicated Chat Assistant Lambda initiates the AI-powered suggestion generation process using Amazon Bedrock.
  3. Asynchronous AI Generation: The Chat Assistant Lambda retrieves the full conversation history from DynamoDB, formats it for the LLM, invokes Amazon Bedrock to generate suggestions, and stores these suggestions in MySQL. This process runs entirely in the background.
  4. Instant Retrieval for Coaches: When a care team member opens a conversation, the pre-generated suggestions are instantly retrieved from MySQL, ready for review.

This decoupled, event-driven approach offers several critical advantages:

Building a serverless AI assistant at Pelago: concept to care in two weeks | Amazon Web Services
  • Scalability: Each Lambda function automatically scales horizontally based on real-time traffic, effortlessly handling message volume spikes during peak hours without manual configuration.
  • Resilience: Failures or spikes in processing for one member do not impact other members or disrupt message delivery.
  • Agility: New capabilities, like the AI assistant, can be added simply by creating a new Lambda function and subscribing it to the SNS topic, with zero changes to existing message-handling code.
  • Performance: By pre-generating suggestions asynchronously, the perceived response time for coaches remains under 100 milliseconds, ensuring a fluid user experience regardless of the LLM processing duration.

Async AI Generation with Amazon Bedrock: Context, Empathy, and Compliance

The Chat Assistant Lambda is responsible for the sophisticated multi-step AI generation workflow. Given that behavioral health conversations can span dozens or hundreds of messages over weeks, the AI assistant’s ability to grasp the full context is paramount.

  1. Conversation History Retrieval: Upon receiving an SNS event, the Lambda function queries Amazon DynamoDB for all previous messages in the conversation. DynamoDB’s single-digit millisecond read performance ensures even lengthy histories (50+ messages) are retrieved in under 20ms, crucial for providing comprehensive context to the LLM.
  2. Context Formatting: The retrieved messages are then transformed into a structured conversation history format, presented to Amazon Bedrock as a coherent dialogue between the user and coach. This ensures the LLM understands the flow and nuances of the interaction.
  3. Bedrock Inference with Prompt Engineering: The Lambda function invokes Claude models via the Amazon Bedrock Runtime API. The prompt engineering is meticulously designed to elicit empathetic and validating responses, prioritizing acknowledgment of the member’s feelings over immediate advice. Prompts are tuned to maintain contextual continuity, referencing earlier messages, and to avoid false optimism or dismissive language. Suggestions are kept concise, mimicking the natural flow of text-based coaching conversations.
  4. Suggestion Storage: Once generated, the AI-powered suggestions are stored in MySQL, ready for instant retrieval by coaches.

Ensuring Data Security and Compliance: A Non-Negotiable Imperative

For any healthcare technology handling Protected Health Information (PHI), HIPAA compliance and robust security measures are not merely beneficial but legally mandated. Pelago implemented multiple AWS security features to ensure HIPAA eligibility and safeguard sensitive data:

  • VPC Endpoints for Bedrock: To prevent PHI from traversing the public internet, Pelago utilizes Amazon Virtual Private Cloud (VPC) endpoints for Amazon Bedrock. This ensures that all model invocations and data exchanges with Bedrock occur entirely within Pelago’s private AWS network, eliminating public internet exposure.
  • Encryption at Rest and In Transit: Data stored in DynamoDB and Amazon RDS (MySQL) is encrypted at rest. All service communications utilize TLS 1.2+ for encryption in transit, further protecting data integrity and confidentiality.
  • Least-Privilege IAM Policies: AWS Identity and Access Management (IAM) policies are rigorously scoped, granting only the minimum necessary permissions to specific resources and actions. This principle of least privilege limits potential access vectors.
  • Audit Logging: Model invocations are meticulously logged to Amazon CloudWatch, capturing essential metadata like message IDs but crucially omitting actual content to protect PHI. These audit trails are vital for compliance and forensic analysis.

These measures collectively ensure that Pelago’s AI assistant operates within a highly secure and compliant environment, a critical factor for adoption in the healthcare industry.

Measuring Success: Performance, Adoption, and Business Impact

The implementation of Pelago’s AI assistant yielded immediate and measurable benefits:

Building a serverless AI assistant at Pelago: concept to care in two weeks | Amazon Web Services
  • Accelerated Response Preparation: The system demonstrated strong early results, reducing response preparation times for care teams by an average of 40%. This efficiency gain directly translates to more capacity for coaches, allowing them to engage with more members or devote more time to complex cases.
  • High Helpfulness Rating: Based on internal Pelago measurements, 79.6% of AI suggestions were rated as helpful by the care team. This high adoption rate underscores the system’s ability to generate relevant and valuable input, validating the prompt engineering and model selection.
  • Seamless Scalability: Operationally, the serverless architecture introduced no new overhead. It seamlessly handled an 8x message volume spike during a seasonal campaign without requiring any configuration changes or manual intervention. This organic scaling eliminates the need for over-provisioning and reduces operational costs.
  • Real-time Responsiveness: The entire workflow, from SNS trigger to suggestion storage, typically completes in less than 4 seconds. More importantly, the care team experiences retrieval times under 100 milliseconds when opening conversations, ensuring a smooth and responsive user interface.

These metrics demonstrate that Pelago not only built a functional AI solution but one that delivers tangible business value and significantly improves the operational efficiency of its care delivery model.

Strategic Technical Decisions and Their Rationale

Beyond the core architecture, several key implementation decisions were crucial for Pelago’s success:

  • Polyglot Cross-Runtime Implementation: The team adopted a polyglot approach, using Python for Lambda functions that interact with Amazon Bedrock. Python’s native Boto3 support for AWS services and its strength in string manipulation made it ideal for prompt building and iteration. In contrast, the retrieval functions were written in TypeScript, aligning with the majority of Pelago’s existing backend code and allowing for the reuse of shared libraries and Zod schemas for type-safe API contracts. This strategic choice enabled the team to leverage the best language for each specific task, optimizing development velocity and code quality.
  • Optimized for Spiky Traffic: Pelago’s US-centric traffic patterns are inherently spiky, with message volumes concentrating during weekday working hours, often seeing 10x or more activity during peak times compared to quiet periods. The pay-per-invocation model of AWS Lambda perfectly accommodates this. Lambda automatically scales out during surges and scales down during off-peak hours, ensuring Pelago only pays for the compute resources actually consumed, avoiding the idle costs associated with traditional, long-lived compute instances or the complexities of managing auto-scaling policies.
  • Dual Storage Strategy and Idempotency: The team strategically chose Amazon DynamoDB for conversation messages and MySQL for assistant suggestions, based on their distinct access patterns. DynamoDB’s high write throughput (100+ writes/sec at peak), single-digit millisecond reads, and automatic scaling made it ideal for storing the voluminous and rapidly changing conversation histories. For assistant suggestions, which have a lighter write load (10-20 writes/sec) but require structured queries, foreign key relationships, and complex analytical joins, a relational database like MySQL was a natural fit. To handle the possibility of duplicate messages from SNS (which can deliver messages more than once), the Chat Assistant Lambda incorporates an idempotency check. Before generating a new suggestion, it verifies if one already exists in MySQL, preventing redundant Amazon Bedrock invocations and ensuring consistent suggestions for coaches.
  • Comprehensive Monitoring and Observability: Pelago established a robust monitoring framework using AWS CloudWatch. Key operational metrics include suggestion generation latency, providing insights into model response times, and retrieval rate, which measures how frequently coaches utilize generated suggestions. This data helps align asynchronous generation with actual usage patterns. Furthermore, coaches can rate each suggestion (thumbs up/down), with these ratings stored in MySQL for future prompt tuning and model evaluation. CloudWatch alarms proactively monitor for critical issues such as Amazon Bedrock throttling or database connection failures, alerting the engineering team to potential problems before they impact the care team.

Broader Implications for Digital Health and Regulated Industries

Pelago’s success with its AI assistant extends beyond the immediate benefits to its care teams and members, offering a compelling blueprint for the broader digital health sector and other highly regulated industries.

  • Scalable Personalization in Healthcare: The model demonstrates a viable path to delivering personalized care at scale, a long-standing challenge in healthcare. By augmenting human coaches with intelligent AI support, organizations can serve more patients without sacrificing the individualized attention critical for effective treatment, particularly in sensitive areas like behavioral health.
  • Mitigating Clinician Burnout: The reduction in response preparation time directly addresses a significant contributor to clinician burnout. By automating repetitive or context-gathering tasks, AI allows healthcare professionals to focus on the human elements of care, empathy, and complex decision-making, improving job satisfaction and retention.
  • Agile Innovation in Regulated Environments: The two-week development cycle showcases that rapid innovation is achievable even within the stringent compliance requirements of healthcare. The combination of managed AWS services (like Bedrock) and serverless architectures provides the necessary agility, security, and scalability for quick prototyping and deployment without compromising regulatory integrity.
  • The "Human-in-the-Loop" as a Best Practice: Pelago’s insistence on human oversight for all AI-generated suggestions is a critical ethical and practical model for AI adoption in sensitive domains. It ensures clinical safety, maintains accountability, and leverages AI as an assistant rather than a replacement for human expertise, building trust in the technology.
  • Blueprint for Other Industries: The architectural patterns—event-driven processing, asynchronous AI generation, secure data handling within VPCs, and robust monitoring—are highly transferable. Industries such as finance, legal, and government, which also deal with sensitive data, high compliance demands, and the need for scalable, personalized interactions, can draw significant lessons from Pelago’s approach.

Conclusion

Pelago’s journey from concept to production deployment of its AI-powered chat assistant exemplifies how small, agile engineering teams in regulated industries can effectively balance speed of innovation with an unyielding commitment to compliance. By strategically combining managed AI services like Amazon Bedrock with a serverless, event-driven architecture, Pelago has not only addressed a critical scaling challenge in substance use disorder support but also established a compelling model for future advancements in digital health. The key patterns—SNS fanout for decoupled processing, asynchronous pre-generation of suggestions for immediate retrieval, the use of VPC endpoints for PHI security, and a focus on prompt engineering with foundation models—underscore a powerful paradigm for delivering intelligent, scalable, and compliant solutions in an increasingly complex healthcare landscape. This innovation holds the promise of making personalized, high-quality care more accessible and sustainable for countless individuals on their path to recovery.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button